package no.ntnu.fp.watch.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import no.ntnu.fp.watch.gui.MasterStatusPanel.MessageButtonListener;
import no.ntnu.fp.watch.gui.MasterStatusPanel.EventLogButtonListener;

public class MasterStatusPanel extends SuperStatusPanel {
	
	private JButton TrendButton;
	private JButton EventlogButton;
	private JButton MessageButton;
	private JLabel statusLabel;
	/**
	 * Parent component.
	 */
	private platformPanel platformPanel;
	
	public MasterStatusPanel(){
		
	}

	public MasterStatusPanel(platformPanel platformPanel, int width, int height)
	{	
		this.platformPanel = platformPanel;
		this.setSize(new java.awt.Dimension(width, height));
		this.setPreferredSize(new Dimension(width, height));
		
		String text = "<html> <h2>Last status change</h2> <br>" +
				" Status duration: <br>" +
				"Time of change: <br><br><br><br>" +
				"Previous Status: </html> ";
		JLabel textLabel = new JLabel(text);
		textLabel.setSize(this.getWidth(), this.getHeight());
		add(textLabel);
		{
			statusLabel = new JLabel();
			statusLabel.setOpaque(true);
			statusLabel.setBackground(Color.red);
			statusLabel.setPreferredSize(new java.awt.Dimension(216, 37));
			this.add(statusLabel);
		}
		{
			MessageButton = new JButton();
			this.add(MessageButton);
			MessageButton.setText("Send Message");
			MessageButton.setPreferredSize(new java.awt.Dimension(216, 40));
			Icon AlarmIcon = new ImageIcon(getClass().getResource("Ikoner/messageIcon.png"));
			MessageButton.setIcon(AlarmIcon);
			MessageButton.addActionListener(new MessageButtonListener());
		}
		{
			EventlogButton = new JButton();
			this.add(EventlogButton);
			EventlogButton.setText("Eventlog");
			EventlogButton.setPreferredSize(new java.awt.Dimension(216, 40));
			Icon LogIcon = new ImageIcon(getClass().getResource("Ikoner/logBook.png"));
			EventlogButton.setIcon(LogIcon);
			EventlogButton.addActionListener(new EventLogButtonListener());
		}
		{
			TrendButton = new JButton();
			this.add(TrendButton);
			TrendButton.setText("Trend");
			TrendButton.setPreferredSize(new java.awt.Dimension(216, 40));
			Icon GraphIcon = new ImageIcon(getClass().getResource("Ikoner/graphIcon.png"));
			TrendButton.setIcon(GraphIcon);
		}

	}
	
	public void setLastStatus(Color c){
		this.statusLabel.setBackground(c);
	}
	
	class EventLogButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e) 
		{
				//JFrame eventLog = new EventLog();
				//eventLog.setVisible(true);
		}
	}
	
	class MessageButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			//int selected = platformPanel.getSelectedElement();
			
			String msg = JOptionPane.showInputDialog(null,"Send Message");
			if(msg != null)
			{
			JOptionPane.showMessageDialog(null,"Sent message: " +"\"" + msg + "\"");
			}
			
		}
	}
	
	public static void main(String args[])
	{
		JFrame frame = new JFrame();
		MasterStatusPanel panel = new MasterStatusPanel(null,330,400);
		frame.getContentPane().add(panel);
		frame.pack();
		frame.setVisible(true);
		frame.setMinimumSize(new Dimension(200,300));
		
		frame.addWindowListener(new java.awt.event.WindowAdapter() {
		    public void windowClosing(java.awt.event.WindowEvent winEvt) {
		        System.exit(0); 
		    }
		});
		
	}
	

}
